package com.hw.one.peach.core.dao;

import com.hw.one.dam2.param.SiteAirParam;
import com.hw.one.peach.core.po.RaiseDustPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/8/4.
 */

@Repository(value = "raiseDustDao")
public class RaiseDustDao implements IRaiseDustDao {


    @Autowired
    private MongoTemplate mongoTemplateStandardSiteData;
    @Override
    public List<RaiseDustPO> findRaiseDustDataBySiteAndTime(SiteAirParam siteAirParam) {
        Criteria criteria = Criteria.where("SITECODE").is(siteAirParam.getSiteCode());
        criteria.and("MONITORTIME").gte(siteAirParam.getStartTime()).lte(siteAirParam.getEndTime());

        Query query = new Query(criteria);

        query.with(new Sort(Sort.Direction.DESC, "MONITORTIME"));
        return mongoTemplateStandardSiteData.find(query, RaiseDustPO.class, "T_DATA_RAISE_DUST_MIN-" + siteAirParam.getEndTime().substring(0, 4));

    }

    @Override
    public List<RaiseDustPO> findRaiseDustNew12DataBySite(SiteAirParam siteAirParam) {
        Criteria criteria = Criteria.where("SITECODE").is(siteAirParam.getSiteCode());
        Query query = new Query(criteria);

        query.with(new Sort(Sort.Direction.DESC, "MONITORTIME")).limit(12);

        return mongoTemplateStandardSiteData.find(query, RaiseDustPO.class, "T_DATA_RAISE_DUST_MIN-" + siteAirParam.getEndTime().substring(0, 4));
    }

    @Override
    public List<RaiseDustPO> findRaiseDustRealDataBySiteCodes(SiteAirParam siteAirParam) {
        Criteria criteria = Criteria.where("SITECODE").in(siteAirParam.getSiteCodes());

        Query query = new Query(criteria);


        return mongoTemplateStandardSiteData.find(query, RaiseDustPO.class, "T_DATA_RAISE_DUST_MIN");
    }
}
